home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 1 / Amiga Tools.iso / egs-tools / egs_demo-version / egs_devels / examples / beginner_gadgets / gadget4.c < prev    next >
C/C++ Source or Header  |  1994-06-06  |  5KB  |  161 lines

  1. /**************************************************************************
  2. *****                       Gadget Demo 4                             *****
  3. *****                                                                 *****
  4. *****                     by John J. Karcher                          *****
  5. *****                                                                 *****
  6. *****                       10 August 1992                            *****
  7. *****                       10 Jan 1993 mvk                           *****
  8. *****                                                                 *****
  9. **************************************************************************/
  10.  
  11. /*
  12.    This program opens up a window with three gadgets in it, using
  13.    egsgadbox.library.  Each gadget prints its own message to the
  14.    console.
  15.  
  16.    This demonstrates how to use CreateHorizBox() to get multiple
  17.    gadgets, and react to different action gadget messages.
  18. */
  19.  
  20. #include <stdio.h>
  21. #include <exec/types.h>
  22. #include <egs/egsintui.h>
  23. #include <egs/egsgadbox.h>
  24. #include <proto/all.h>
  25. #include <egs/proto/all.h>
  26.  
  27.  
  28. #define  ACTION_GAD_ID     1000
  29. #define  HELP_GAD_ID       1001
  30. #define  LONG_GAD_ID       1002
  31.  
  32. BYTE  CreateWindow(void);
  33. BYTE  CreateGfx(void);
  34.  
  35. struct Library *EGSIntuiBase;
  36. struct Library *EGBBase;
  37.  
  38. struct EB_GadContextNode   *GadCon;
  39. struct EI_Window           *Win;
  40.  
  41.  
  42. BYTE  CreateGfx(void)
  43. {
  44.    EB_GadBoxPtr           root, b1;
  45.    BYTE  ret = 0;
  46.  
  47.    if (GadCon = EB_CreateGadContext(NULL, NULL, -1, -1))
  48.      {
  49.       root = EB_CreateVertiBox(GadCon);
  50.       EB_AddLastSon(root, EB_CreateVertiFill(GadCon, TRUE, 0));
  51.  
  52.       b1 = EB_CreateHorizBox(GadCon);
  53.       EB_AddLastSon(root, b1);
  54.       EB_AddLastSon(b1, EB_CreateHorizFill(GadCon, TRUE, 0));
  55.       EB_AddLastSon(b1, EB_CreateTextAction(GadCon, "_Push Me", ACTION_GAD_ID, EB_FILL_ALL));
  56.       EB_AddLastSon(b1, EB_CreateHorizFill(GadCon, TRUE, 0));
  57.       EB_AddLastSon(b1, EB_CreateTextAction(GadCon, "_Leave Me Alone", LONG_GAD_ID, EB_FILL_ALL));
  58.       EB_AddLastSon(b1, EB_CreateHorizFill(GadCon, TRUE, 0));
  59.       EB_AddLastSon(b1, EB_CreateTextAction(GadCon, "_Help Me", HELP_GAD_ID, EB_FILL_ALL));
  60.       EB_AddLastSon(b1, EB_CreateHorizFill(GadCon, TRUE, 0));
  61.  
  62.       EB_AddLastSon(root, EB_CreateVertiFill(GadCon, TRUE, 0));
  63.  
  64.  
  65.       root = EB_CreateMasterWindow(GadCon,Win,root);
  66.  
  67.       if (EB_ProcessGadBoxes(GadCon, root))
  68.         {
  69.          ret = 1;
  70.         }
  71.      }
  72.  
  73.    return ret;
  74. }
  75.  
  76. BYTE  CreateWindow(void)
  77. {
  78.    BYTE  ret = 0;
  79.  
  80.    if (CreateGfx())
  81.      {
  82.       GadCon->NewWin->Title              = "EGS Gadget Demo 4";
  83.       GadCon->NewWin->Flags             &= ~EI_SMART_REFRESH;
  84.       GadCon->NewWin->Flags             |= (EI_SIZEBBOTTOM | EI_WINDOWCENTER);
  85.       GadCon->NewWin->IDCMPFlags        |= (EI_iCLOSEWINDOW | EI_iGADGETUP | EI_iSIZEVERIFY | EI_iNEWSIZE);
  86.       GadCon->NewWin->Bordef.SysGadgets |= (EI_WINDOWCLOSE | EI_WINDOWSIZE);
  87.       if (Win = EI_OpenWindow(GadCon->NewWin))
  88.         {
  89.          ret = 1;
  90.         }
  91.      }
  92.  
  93.    return ret;
  94. }
  95.  
  96. main()
  97. {
  98.    struct EI_EIntuiMsg  *IMsg;
  99.    struct EI_Gadget     *TempGad;
  100.    BYTE  quit = 0;
  101.  
  102.    if (EGSIntuiBase = OpenLibrary("egsintui.library", 0))
  103.      {
  104.       if (EGBBase = OpenLibrary("egsgadbox.library", 0))
  105.         {
  106.          if (CreateWindow())
  107.            {
  108.             while (!quit)
  109.               {
  110.                WaitPort(Win->UserPort);
  111.                if (IMsg = (struct EI_EIntuiMsg *)GetMsg(Win->UserPort))
  112.                  {
  113.                   if (IMsg->Class == EI_iCLOSEWINDOW)
  114.                     {
  115.                      quit = 1;
  116.                     }
  117.                   if (IMsg->Class == EI_iGADGETUP)
  118.                     {
  119.                      TempGad = (struct EI_Gadget *)IMsg->IAddress;
  120.                      if (TempGad->GadgetID == ACTION_GAD_ID)
  121.                        {
  122.                         printf("You pressed me!\n");
  123.                        }
  124.                      if (TempGad->GadgetID == LONG_GAD_ID)
  125.                        {
  126.                         printf("You're not leaving me alone!\n");
  127.                        }
  128.                      if (TempGad->GadgetID == HELP_GAD_ID)
  129.                        {
  130.                         printf("You helped me!\n");
  131.                        }
  132.                     }
  133.                   if (IMsg->Class == EI_iSIZEVERIFY)
  134.                     {
  135.                      EI_RemoveGList(Win, GadCon->First, GadCon->Num);
  136.                      EB_DeleteGadContext(GadCon);
  137.                      GadCon = NULL;
  138.                     }
  139.                   if (IMsg->Class == EI_iNEWSIZE)
  140.                     {
  141.                      EI_LockIntuition();
  142.                      CreateGfx();
  143.                      if (GadCon)
  144.                        {
  145.                         EI_AddGList(Win, GadCon->First, GadCon->Num);
  146.                        }
  147.                      EI_UnlockIntuition();
  148.                     }
  149.                   ReplyMsg((struct Message *)IMsg);
  150.                  }
  151.               }
  152.            }
  153.          if (Win) EI_CloseWindow(Win);
  154.          if (GadCon) EB_DeleteGadContext(GadCon);
  155.          CloseLibrary(EGBBase);
  156.         }
  157.       CloseLibrary(EGSIntuiBase);
  158.      }
  159. }
  160.  
  161.